package coml.jiyun.hp.day01;

import android.os.Bundle;
import android.widget.TextView;

import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import coml.jiyun.hp.day01.adapter.MainAdapter;
import coml.jiyun.hp.day01.fragment.HomeFragment;
import coml.jiyun.hp.day01.fragment.WebFragment;

public class MainActivity extends AppCompatActivity {

    /**
     * 首页
     */
    private TextView mToolTv;
    private Toolbar mMainTool;
    private ViewPager mMainVp;
    private TabLayout mMainTab;
    private ArrayList<Fragment> fragments;
    private ArrayList<String> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mToolTv = (TextView) findViewById(R.id.tool_tv);
        mMainTool = (Toolbar) findViewById(R.id.main_Tool);
        mMainVp = (ViewPager) findViewById(R.id.main_vp);
        mMainTab = (TabLayout) findViewById(R.id.main_tab);

        mMainTool.setTitle("");

        fragments = new ArrayList<>();
//        fragments.add(new HomeFragment());
//        fragments.add(new WebFragment());

        list = new ArrayList<>();
        list.add("首页");
        list.add("网页");

        for (int i = 0; i < 2; i++) {
            fragments.add(new HomeFragment());
        }

        MainAdapter mainAdapter = new MainAdapter(getSupportFragmentManager(), fragments, list);
        mMainVp.setAdapter(mainAdapter);
        mMainTab.setupWithViewPager(mMainVp);
    }
}
